package com.kfm.hotel.controller;


import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.github.pagehelper.PageInfo;
import com.kfm.hotel.domain.IntakeInfo;
import com.kfm.hotel.domain.Room;
import com.kfm.hotel.domain.SysUser;
import com.kfm.hotel.service.IntakeInfoService;
import com.kfm.hotel.util.Constant;
import com.kfm.hotel.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

@RestController
@RequestMapping("/checkout")
public class CheckOutController {
    @Autowired
    private IntakeInfoService intakeInfoService;
    /**
     * 视图层
     */
    @GetMapping
    public ModelAndView index(){
        ModelAndView andView = new ModelAndView("checkout/index");
        return andView;
    }
    /**
     * 分页
     */
    @GetMapping("/list")
    public R list(@RequestParam(defaultValue = "1") Integer page,
                  @RequestParam(defaultValue = "10") Integer limit,
                  IntakeInfo entity){
        PageInfo<IntakeInfo> pageInfo= intakeInfoService.listCheckOut(entity,page,limit);
        return R.ok(pageInfo);

    }
    /**
     * 退房id
     */
    @GetMapping("/{id}")
    public ModelAndView checkOut(@PathVariable Integer id){
        ModelAndView modelAndView = new ModelAndView("checkout/checkout");
        modelAndView.addObject("id",id);
        return modelAndView;
    }
    /**
     * 联查
     */
    @GetMapping("/get/{id}")
    public R getInfo(@PathVariable Integer id){
        IntakeInfo intakeInfo=intakeInfoService.getByIdDeep(id,config->config.loop(true));
        return R.ok(intakeInfo);
    }
    /**
     * 退房
     */
    @PostMapping("/checkout")
    public R checkout(@RequestBody IntakeInfo intakeInfo, @SessionAttribute(Constant.LOGIN_USER)SysUser sysUser){
          intakeInfoService.checkOut(intakeInfo,sysUser.getId());
          return R.ok("退房成功");
    }

}
